Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are zero-based.
http://www.lintcode.com/problem/two-sum/
Solution #1 - Brute Force search. O(n) Space, O(n^2) time
1 | class Solution: |
Solution #2 - Double pointer. O(n) Space, O(nlogn)time
Solution #3 - Hash. O(n) Space, O(n)time
1 | class Solution: |